home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BBS Toolkit
/
BBS Toolkit.iso
/
rbbs_pc
/
overm82.zip
/
MSG2TXT.ZIP
/
MSG2TXT.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-02-24
|
7KB
|
273 lines
/* MSG2TXT.C
*------------------------------------------------------------------------
*
* Program to convert a RBBS Messages file to text format
*
* Tom Collins
* 01-20-90
*/
#pragma pack(1)
typedef unsigned int Bit;
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <io.h>
#include <stdarg.h>
#include <fcntl.h>
#include <sys\types.h>
#include <sys\stat.h>
#include <dos.h>
#include "rbbs.h"
#define TRUE 1
#define FALSE 0
#define RBBS_EOL '\xE3'
#define DELETED_MESSAGE '\xE2'
char *trim_string(char *);
void txt_printf(FILE *,int,char *,...);
int lines_printed;
int use_page_feeds;
void main(int argc,char **argv)
{
int fhin;
FILE *fpout;
char *full_txt, *txt, *ptr;
int txt_size;
int first_rec, last_rec, next_avail_rec;
int recs_in_msg;
int message_number, starting_message_number;
int anything_exported;
int no_privates;
int i, j;
int msgs_processed, recs_processed;
int recs_to_process;
struct rbbs_checkpoint chkpt;
struct rbbs_message_header hdr;
struct dosdate_t ddate;
struct dostime_t dtime;
if (argc < 3)
{
printf("Usage: MSG2TXT Messages_File_Name Text_File_Name [Start] [/NOPAGE] [/NOPRIVATE]\n\n");
printf(" Messages_File_Name = Name of your RBBS messages file\n");
printf(" Text_File_Name = Name of the file to write the text to\n");
printf(" Start (Optional) = Start exporting at what message number\n");
printf(" /NOPAGE (Optional) = Don't put page feeds in the output file\n");
printf(" /NOPRIVATE (Optional) = Don't export private messages\n");
exit(1);
}
printf("MSG2TXT v0.02C 01-20-90 - Super Dooper RBBS Message to Text Converter\n\n");
printf("Input File : %s\n",strupr(argv[1]));
printf("Output File: %s\n\n",strupr(argv[2]));
starting_message_number = 0;
use_page_feeds = TRUE;
no_privates = FALSE;
anything_exported = FALSE;
if (argc > 3)
{
starting_message_number = atoi(argv[3]);
for (i = 3; i < argc; i++)
{
if (strcmp(strupr(argv[i]),"/NOPAGE") == 0)
{
use_page_feeds = FALSE;
}
if (strcmp(strupr(argv[i]),"/NOPRIVATE") == 0)
{
no_privates = TRUE;
}
}
}
fhin = open(argv[1],O_RDONLY|O_BINARY);
if (fhin < 0)
{
printf("Error Opening Messages File %s - Program Aborted\n",argv[1]);
exit(1);
}
fpout = fopen(argv[2],"wt");
if (fpout == NULL)
{
printf("Error Opening Text File %s - Program Aborted\n",argv[2]);
exit(1);
}
read(fhin,(char *)&chkpt,sizeof(chkpt));
first_rec = atoi(chkpt.first_message);
last_rec = atoi(chkpt.last_message);
next_avail_rec = atoi(chkpt.next_message);
i = first_rec;
msgs_processed = recs_processed = lines_printed = 0;
recs_to_process = next_avail_rec - first_rec;
printf("Records to Process: %i\n",recs_to_process);
if (use_page_feeds)
{
txt_printf(fpout,0,"\f");
}
txt_printf(fpout,1,"MSG2TXT Conversion: %s -> %s",argv[1],argv[2]);
_dos_getdate(&ddate);
_dos_gettime(&dtime);
txt_printf(fpout,1,"Converted: %02u-%02u-%4u %02u:%02u:%02u",
ddate.month, ddate.day, ddate.year,
dtime.hour, dtime.minute, dtime.second);
if (starting_message_number != 0)
{
txt_printf(fpout,3,"Beginning Export at Message # %i",
starting_message_number);
}
else
txt_printf(fpout,2,"");
lseek(fhin,((long)(first_rec-1)*128L),SEEK_SET);
do {
read(fhin,(char *)&hdr,sizeof(hdr));
recs_in_msg = atoi(hdr.message_rec);
if (recs_in_msg <= 0)
{
recs_in_msg = 1;
}
message_number = atoi(hdr.mess_number);
if (message_number < starting_message_number ||
(hdr.read_only == '*' && no_privates) ||
hdr.active_indicator == DELETED_MESSAGE)
{
lseek(fhin,(long)((recs_in_msg-1)*128),SEEK_CUR);
}
else
{
txt_printf(fpout,1," Msg #: %4.4s",&(hdr.read_only));
txt_printf(fpout,1," From: %31.31s Sent: %8.8s %5.5s",hdr.message_from,hdr.message_date_sent,hdr.message_time);
txt_printf(fpout,1," To: %22.22s Rcvd: -NO-",hdr.message_to);
txt_printf(fpout,2," Subj: %25.25s",hdr.message_subject);
txt_size = (recs_in_msg-1)*128;
full_txt = malloc(txt_size + 1);
read(fhin,full_txt,txt_size);
full_txt[txt_size] = '\0';
txt = full_txt;
for (j = 0; j < txt_size; j++)
{
if (full_txt[j] == RBBS_EOL)
{
full_txt[j] = '\0';
trim_string(txt);
if (txt[0] != 0x01 && strstr(txt,"SEEN-BY") != txt)
{
txt_printf(fpout,1,"%s",txt);
}
txt = &full_txt[j+1];
}
}
txt_printf(fpout,1,"");
free(full_txt);
anything_exported = TRUE;
}
i += recs_in_msg;
msgs_processed++;
recs_processed += recs_in_msg;
printf(" %i Msgs %i Recs\r",msgs_processed,recs_processed);
}
while (i < next_avail_rec);
if (!anything_exported)
{
txt_printf(fpout,1,"No New Messages Found...");
}
printf("Done Processing \n");
fclose(fpout);
close(fhin);
exit(0);
}
/* TRIM_STRING
*----------------------------------------------------------------------------
*
* Removes trailing spaces and '\n's
* from a string.
*
* Globals Used:
* <none>
*
* Returns:
* The trimmed string
*/
char *trim_string(char *s)
{
int i;
/*
i = 0;
while (s[i] != '\0')
if (s[i] == ' ')
i++;
else
break;
strcpy(s,&s[i]);
*/
for (i = strlen(s)-1; i >= 0; i--)
if (s[i] == ' ' || s[i] == '\n' || s[i] == '\r')
s[i] = '\0';
else
break;
return(s);
}
void txt_printf( FILE *fp, int returns, char *p, ...)
{
int i;
va_list arg_ptr;
char *buf;
/*
* Initalize
*/
buf = malloc(8192);
/*
* Process input string and optional parameters
*/
va_start( arg_ptr, p);
i = vsprintf( buf, p, arg_ptr);
fputs( buf, fp);
for (i = 0; i < returns; i++)
{
fputs("\n",fp);
lines_printed++;
if (lines_printed == 60 && use_page_feeds)
{
fputs("\f\n\n\n",fp);
lines_printed = 0;
}
}
/*
* Cleanup
*/
free( buf);
}